import redis.asyncio as aioredis
from config import settings


async def get_redis():
    redis = await aioredis.from_url(
        f"redis://:{settings.REDIS_PASSWORD}@{settings.REDIS_HOST}:{settings.REDIS_PORT}",
        db=settings.REDIS_DB
    )
    try:
        yield redis
    finally:
        await redis.close()

